<?php
    header('content-type:text/html;charset="utf-8') ;


    // 连接数据库
    $host = 'localhost:3306';
    $name = 'root';
    $pwd = 'root';
    $dbname = 'test2';
    $conn = mysqli_connect($host , $name , $pwd , $dbname);
    // 数据库是否连接
    if(!$conn) {
        die('数据库连接失败');
    }
    
    $id = $_POST['id'];

    $obj = [] ;
    
    // 执行一个SQL语句
    $sql = "select * from goods_list where goods_id = $id " ;
     // 执行sql语句  第一个参数表示连接  第二个参数表示sql语句
    $res = mysqli_query($conn , $sql) ;
    // 数据库中的结果集转成关联数组
    $arr = mysqli_fetch_array($res) ;

    $data = [];

    if($arr) {
        $data['id'] = $arr['goods_id'] ;
        $data['name'] = $arr['goods_name'] ;
        $data['title'] = $arr['goods_title'] ;
        $data['des'] = $arr['goods_des'] ;
        $data['img'] = $arr['goods_img'] ;
        $data['price'] = $arr['goods_price'] ;
        $data['type'] = $arr['goods_type'] ;


        $obj['status'] = true ;
        $obj['msg'] = '数据请求成功';
        $obj['data'] = $data ;
    } else {
        $obj['status'] = false ;
        $obj['msg'] = '服务器错误';
    }

    echo(json_encode($obj));